//
//  TLShortStoryLockTableViewCell.m
//  WXReader
//
//  Created by huaya on 2025/1/14.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLShortStoryLockTableViewCell.h"

@interface TLShortStoryLockTableViewCell ()
@property (weak, nonatomic) IBOutlet UIView *svipView;
@property (weak, nonatomic) IBOutlet UIView *unlockView;

@property (weak, nonatomic) IBOutlet UILabel *topRightLab;
@property (weak, nonatomic) IBOutlet UILabel *svipViewTitleOneLab;
@property (weak, nonatomic) IBOutlet UILabel *svipViewTitleTwoLab;

@property (weak, nonatomic) IBOutlet UILabel *balanceLab;

@property (weak, nonatomic) IBOutlet UILabel *unlockViewTitleOneLab;
@property (weak, nonatomic) IBOutlet UIButton *autoBuyBtn;


@end

@implementation TLShortStoryLockTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _svipView.layer.cornerRadius = _svipView.frame.size.height/2;
    _unlockView.layer.cornerRadius = _unlockView.frame.size.height/2;
    _topRightLab.layer.cornerRadius = _topRightLab.frame.size.height/2;
    _topRightLab.hidden = YES;
    
    UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (self.vipBlock) {
            self.vipBlock();
        }
    }];
    [self.svipView addGestureRecognizer:tapGest];
    
    UITapGestureRecognizer *tap2Gest = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (self.coinsBlock) {
            self.coinsBlock();
        }
    }];
    [self.unlockView addGestureRecognizer:tap2Gest];
    
    NSNumber *isAuto = [[NSUserDefaults standardUserDefaults] objectForKey:IS_AUTO_BUY_NEXT_CHAPTER];
    
    if (isAuto.intValue == 1) {
        self.autoBuyBtn.selected = YES;
    }else{
        self.autoBuyBtn.selected = NO;
    }
    
}
- (void)setDataContentModel:(TLBookContentModel *)dataContentModel{
    if (dataContentModel) {
        _dataContentModel = dataContentModel;
        
        _svipViewTitleOneLab.text = [NSString stringWithFormat:@"Get VIP: Only  $%@",dataContentModel.osGoodsVO1.price];
        
        _svipViewTitleTwoLab.text = dataContentModel.osGoodsVO1.hint2;
        
        _unlockViewTitleOneLab.text = [NSString stringWithFormat:@"Permanent unlock: %@ Coins/Bonus",dataContentModel.chapterCoinNum];
        
        if (TL_UserInfoManager.isLogin) {
            
            _balanceLab.text = [NSString stringWithFormat:@"My wallet:%@ Coins %@ Bonus",dataContentModel.coinNum,dataContentModel.bonusNum];
            
        }else{
            
            _balanceLab.text = [NSString stringWithFormat:@"My wallet:0 Coins 0 Bonus"];
            
        }
        
    }
}
- (void)setDataModel:(TLBookListForSSModel *)dataModel{
    if (dataModel) {
        _dataModel = dataModel;
        
        _svipViewTitleOneLab.text = [NSString stringWithFormat:@"Get VIP: Only $%@"
                                     ,dataModel.osGoodsVO1.price];
        
        _svipViewTitleTwoLab.text = dataModel.osGoodsVO1.hint2;
        
        _unlockViewTitleOneLab.text = [NSString stringWithFormat:@"Permanent unlock: %@ Coins/Bonus",dataModel.chapterCoinNum];
        
        if (TL_UserInfoManager.isLogin) {
            
            _balanceLab.text = [NSString stringWithFormat:@"My wallet:%@ Coins %@ Bonus",dataModel.coinNum,dataModel.bonusNum];
            
        }else{
            
            _balanceLab.text = [NSString stringWithFormat:@"My wallet:0 Coins 0 Bonus"];
            
        }
        
    }
}
- (IBAction)autoBuyAction:(id)sender {
    
    UIButton *btn = (UIButton*)sender;
    
    btn.selected = !btn.selected;
    
    int isOn = btn.selected;
    
    [[NSUserDefaults standardUserDefaults] setObject:@(isOn) forKey:IS_AUTO_BUY_NEXT_CHAPTER];
    
}
- (void)setUIForBuyView{
    
    [self.contentView setBackgroundColor:[UIColor clearColor]];
    [self setBackgroundColor:[UIColor clearColor]];
    
    [self.unlockView setBackgroundColor:[UIColor clearColor]];
    self.unlockView.layer.borderWidth = 1;
    self.unlockView.layer.borderColor = [UIColor colorWithHexString:@"F5AE4C"].CGColor;
    
}
- (void)refreshUI{
    
    [self.contentView setBackgroundColor:[[MKReaderCfg shared] bgColor]];
    
    if ([MKReaderCfg shared].bgColorIndex.intValue == 0) {
        
        [self.unlockView setBackgroundColor:[UIColor whiteColor]];
        
        self.unlockViewTitleOneLab.textColor = [UIColor hex_9E6DFC];
        
    }else{
        
        [self.unlockView setBackgroundColor:[UIColor hex_313538]];
        
        self.unlockViewTitleOneLab.textColor = [UIColor whiteColor];
        
    }
    
}

@end
